package app;

import java.util.ArrayList;

public class Essay {

	public int id;
	public String subject;
	public String author;
	public ArrayList<String> paragraphs = new ArrayList<String>();
	public ArrayList<String> sentences = new ArrayList<String>();
	public ArrayList<String> words = new ArrayList<String>();
	
	public Essay(int id, String subject, String author, String contents)
	{
		this.id = id;
		this.subject = subject;
		this.author = author;
		split(contents);
	}
	
	public Essay(String subject, String author, String contents)
	{
		this.subject = subject;
		this.author = author;
		split(contents);
	}
	
	/**
	 * Split the contents string into paragraphs
	 * @param contents The file contents
	 */
	public void split(String contents)
	{
		//Split the contents to paragraphs
		String[] paras = contents.split("[\n\r]+[\n\r\t]*");
		for(int i=0;i<paras.length;i++){
			if(!paras[i].equals(""))
				paragraphs.add(paras[i]);
		}
		//Split the contents to sentences
		String[] sents = contents.split("[.?!]+\\s+(?=[A-Z])");
		for(int i=0;i<sents.length;i++){
			if(!sents[i].equals(""))
				sentences.add(sents[i]);
		}
	}
	
	public String getSentence(int number)
	{
		try{
			return (String)sentences.get(number);
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}
}
